// xc/components/searchpage/searchpage.js
//op=search
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    showsearch: {
      type: Boolean,
      value:true
    },
    hotsearch:{
      type: Array,
      value:[]
    }
   
  },

  /**
   * 组件的初始数据
   */
  data: {
    searchkeys:""
  },
  lifetimes: {
    created() { //刚创建
      // wx.hideTabBar()
    },
    attached() { //节点

    },
    ready() {
      this.getstore()
    },
    moved() {

    },
    detached() {

    },

  },
  /**
   * 组件的方法列表
   */
  methods: {
    
    getstore() {
      var searchkeys = wx.getStorageSync('searchkeys')
      if(searchkeys){
        this.setData({
          searchkeys: JSON.parse(searchkeys) 
        })
      }
      
    },
    clearstore(){
      var that=this;
      wx.removeStorage({
        key: 'searchkeys',
        success (res) {
          wx.showToast({
            icon:"none",
            title: '清除成功',
          })
          that.setData({
            searchkeys:""
          })
        }
      })
    },
    onSearch(e){
      var dataset=e.currentTarget.dataset
      var key="";
      if(dataset.name){
        key=dataset.name
      }else{
        key=this.data.searchkey
      }
      if(key){
        this.setData({
          showsearch:false
        })
        this.triggerEvent('onSearch',key ) 
      }else{
        wx.showToast({
          icon:"error",
          title: '请输入关键词',
        })
      }
      
    },
    Backfunc(){
      wx.navigateBack({
        delta:1
      })
    },
  }
})